<?$this->load->view("/inc/header_inc")?>
   <?$this->load->view("/inc/nav_inc")?>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li><a href="/home">首页</a> </li>
                <li class="active">修改密码</li>
            </ul>
        </div>
       <div class="main-content">
        <!--add user start-->
	        <div class="row">
		        <div class="col-md-6">
		            <div id="myTabContent" class="tab-content">
		                <div class="tab-pane active in" id="home">
		                    <p class="text-info">说明：帶*的为必填项。</p>
		                    <form id="pwdForm" class="form-horizontal" name="pwdForm" method="post" action="/admin/user/updatePwd">
		                        <input type="hidden" name="id" id="id" value="<?=$user['id']?>" >
		                        <div class="form-group">
		                            <label class="col-sm-2 control-label">当前密码</label>
		                            <div class="col-sm-8">
		                                <input type="password" id="oldpwd" name="oldpwd" value="" class="form-control" maxlength="10">
		                            </div>
		                            <div class="col-sm-2"><p class="text-warning">(*)</p></div>
		                        </div>

		                        <div class="form-group">
		                            <label class="col-sm-2 control-label">新密码</label>
		                            <div class="col-sm-8">
		                                <input type="password" id="pwd" name="pwd"   class="form-control" maxlength="30">
		                            </div>
		                            <div class="col-sm-2"><p class="text-warning">(*)</p></div>
		                        </div>
		                        <div class="form-group">
		                            <label class="col-sm-2 control-label">确认新密码</label>
		                            <div class="col-sm-8">
		                                <input type="password" id="pwd2" name="pwd2"   class="form-control" maxlength="30">
		                            </div>
		                            <div class="col-sm-2"><p class="text-warning">(*)</p></div>
		                        </div>
		                        <div class="form-group">
		                           <div class="btn-toolbar list-toolbar">
		                              <input type="submit" id="useraddbtn" name="useraddbtn" class="btn btn-success pull-right" value="保存"></input>
		                             </div>
		                        </div>
		                </div>
		            </div>
		        </div>
	        </div>
	        <!--add user end-->
	    </div>
        <div class="modal small fade" id="successModal" tabindex="-1" role="dialog" aria-labelledby="successModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel">成功</h3>
                    </div>
                    <div class="modal-body">
                        <p class="error-text"><i class="fa fa-success modal-icon" ></i><span id="modal-success-content"></span></p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true" id="continue-btn">继续操作</button>
                        <button class="btn btn-danger" data-dismiss="modal" id="finish-btn">结束操作</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal small fade" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="errorModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="errorModalLabel">错误</h3>
                    </div>
                    <div class="modal-body">
                        <p class="error-text"><i class="fa fa-warning modal-icon" ></i><span id="modal-error-content"></span></p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">继续操作</button>
                        <button class="btn btn-danger" data-dismiss="modal">结束操作</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
     <script src="/static/javascripts/jquery-1.11.3.min.js" type="text/javascript"></script>
     <script src="/static/javascripts/bootstrap.min.js"></script>
     <script src="/static/javascripts/jquery.validate.min.js"></script>
     <script type="text/javascript">
	    $(function(){
	        var form = $( "#pwdForm" );
	        form.removeAttr("novalidate");
	        form.validate({
	            rules: {
	                oldpwd: {
	                    required:true,
	                    maxlength:20
	                },
	                pwd:{
	                    required:true,
	                    maxlength:20
	                },
	                pwd2:{
	                    required:true,
	                    equalTo:"#pwd"
	                }
	            },
	            messages: {
	                oldpwd:{
	                    required:"请输入当前密码",
	                    maxlength:"不能多于{0}位"
	                },
	                pwd:{
	                    required:"请输入新密码",
	                    maxlength:"不能多于{0}位"
	                },
	                pwd2:{
	                    required:"请确认新密码",
	                    equalTo:"确认密码与新密码不同"
	                }
	            },
	            submitHandler:function (form) {
	                $.ajax({
	                    type: $(form).attr('method'),
	                    url: $(form).attr('action'),
	                    data: $(form).serialize(),
	                    dataType : 'json'
	                }).done(function (data) {
	                    if (data.code == 1) {
	                            showSuccess(data.msg);                           
	                        } else {
	                            showError(data.msg);
	                        }
	                    });
	                  return false; // required to block normal submit since you used ajax
	             }
	        });
	        $("#continue-btn").click(function(){
	            window.location.reload();
	        });
	        $("#finish-btn").click(function(){
	            window.location.href="/admin/user/pwd";
	        });
	    });

	    function showSuccess(content)
	    {
	        $('#successModal').modal('toggle');
	        $('#successModal').modal('show');
	        $("#modal-success-content").text(content);
	    }

	    function showError(content){
	        $('#errorModal').modal('toggle');
	        $('#errorModal').modal('show');
	        $("#modal-error-content").text(content);
	    }
	</script>
</body>
</html>
